#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
using namespace std;

class Solution {
public:
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
        set<vector<int>> S;
        sort(nums.begin(),nums.end());
        return func(nums,S);
       
    }
    vector<vector<int>> func(vector<int>& nums,set<vector<int>>& S){
         if(nums.empty()){
            vector<vector<int>> temp = {{}};
            return temp;
        }
        vector<int> T(nums.begin()+1,nums.end());
        int R = *nums.begin();
        vector<vector<int>> result = func(T,S);
        int size = result.size();
        for(int i = 0;i<size;++i){
            vector<int> D = result[i];
            D.push_back(R);
            if(S.insert(D).second)
                result.push_back(D);
        }
        return result;
        
    }
};


int main(){
    Solution S;
    vector<int> nums = {1,2,2};
    vector<vector<int>> result = S.subsetsWithDup(nums);
    return 0;
}